from django import forms
from skran import models 
from django.forms.widgets import Textarea

class ProjectForm(forms.ModelForm):
        
    class Meta:
        model = models.Project
        fields = ('name','description')
        
        widgets = {
            'description': Textarea(attrs={'cols': 30, 'rows': 5}),
        }
        
    def clean(self):
        return self.cleaned_data
        
    def save(self, user=None, commit=True):
        
        project = models.Project()
        project.name = self.cleaned_data['name']
        project.description =  self.cleaned_data['description']
        project.created_by = user.username
        project.updated_by = user.username
        
        if commit:
            project.save()
            project.user = [user]
            project.save()
        